export function formatDate(data, formatStr) {
    if (!formatStr || typeof formatStr != 'string') formatStr = "yyyy-MM-dd HH:mm";
    var date = data;
    switch (typeof data) {
        case "string":
            if (navigator.userAgent.indexOf('Firefox') > -1 || (!!window.ActiveXObject || "ActiveXObject" in window)) {
                date = new Date(data.replace(/ /g, 'T').replace(/\//g, "-"));
            } else {
                date = new Date(data.replace(/T/g, ' ').replace(/-/g, "/"));
            }
            break;
        case "number":
            date = new Date(data);
            break;
    }
    if (!(date instanceof Date))
        return data;
    var dict = {
        "yyyy": date.getFullYear(),
        "M": date.getMonth() + 1,
        "d": date.getDate(),
        "H": date.getHours(),
        "m": date.getMinutes(),
        "s": date.getSeconds(),
        "MM": ("" + (date.getMonth() + 101)).substr(1),
        "dd": ("" + (date.getDate() + 100)).substr(1),
        "HH": ("" + (date.getHours() + 100)).substr(1),
        "mm": ("" + (date.getMinutes() + 100)).substr(1),
        "ss": ("" + (date.getSeconds() + 100)).substr(1)
    };
    return formatStr.replace(/(yyyy|MM?|dd?|HH?|ss?|mm?)/g, function () {
        return dict[arguments[0]];
    });
}

export function toDate(strDate) {
    let date;
    if (navigator.userAgent.indexOf('Firefox') > -1 || (!!window.ActiveXObject || "ActiveXObject" in window)) {
        date = new Date(strDate.replace(/ /g, 'T').replace(/\//g, "-"));
    } else {
        date = new Date(strDate.replace(/T/g, ' ').replace(/-/g, "/"));
    }
    return date;
}
